package com.mjing.result;

import com.alibaba.fastjson.JSON;

import java.io.Serializable;

/**
 * @param
 * @author ming
 * @Description 结果返回工具类
 * @Date 2019-01-22
 */
public class ResultUtil implements Serializable {

    public static final Integer SUCCESS_CODE = 200;
    public static final Integer ERROR_CODE = 400;

    public static final String SERARCH_SUCCESS = "成功";
    public static final String DELETE_SUCCESS = "删除成功";
    public static final String UPDATE_SUCCESS = "更新成功";
    public static final String INSERT_SUCCESS = "新增成功";


    public static JsonResult success() {
        return getResult(SUCCESS_CODE, SERARCH_SUCCESS, null);
    }

    public static JsonResult successSer() {
        return getResult(SUCCESS_CODE, SERARCH_SUCCESS, null);
    }

    public static JsonResult successSer(String msg) {
        return getResult(SUCCESS_CODE, msg, null);
    }

    public static JsonResult successSer(Object object) {
        return getResult(SUCCESS_CODE, SERARCH_SUCCESS, object);
    }

    public static JsonResult success(Object object) {
        return getResult(SUCCESS_CODE, SERARCH_SUCCESS, object);
    }

    public static JsonResult successSer(String msg, Object object) {
        return getResult(SUCCESS_CODE, msg, object);
    }

    public static JsonResult success(String msg, Object object) {
        return getResult(SUCCESS_CODE, msg, object);
    }

    public static JsonResult errorSer(String msg) {
        return getResult(ERROR_CODE, msg, null);
    }

    public static JsonResult errorSer(Integer code, String msg) {
        return getResult(code, msg, null);
    }

    public static JsonResult errorSer(Integer code, String msg, Object obj) {
        return getResult(code, msg, obj);
    }


    public static JsonResult successDel() {
        return getResult(SUCCESS_CODE, DELETE_SUCCESS, null);
    }

    public static JsonResult successDel(String msg) {
        return getResult(SUCCESS_CODE, msg, null);
    }

    public static JsonResult successDel(Object object) {
        return getResult(SUCCESS_CODE, DELETE_SUCCESS, object);
    }

    public static JsonResult successDel(String msg, Object object) {
        return getResult(SUCCESS_CODE, msg, object);
    }

    public static JsonResult errorDel(String msg) {
        return getResult(ERROR_CODE, msg, null);
    }

    public static JsonResult errorDel(Integer code, String msg) {
        return getResult(code, msg, null);
    }

    public static JsonResult errorDel(Integer code, String msg, Object obj) {
        return getResult(code, msg, obj);
    }


    public static JsonResult successUpdate() {
        return getResult(SUCCESS_CODE, UPDATE_SUCCESS, null);
    }

    public static JsonResult successUpdate(String msg) {
        return getResult(SUCCESS_CODE, msg, null);
    }

    public static JsonResult successUpdate(Object object) {
        return getResult(SUCCESS_CODE, UPDATE_SUCCESS, object);
    }

    public static JsonResult successUpdate(String msg, Object object) {
        return getResult(SUCCESS_CODE, msg, object);
    }

    public static JsonResult errorUpdate(String msg) {
        return getResult(ERROR_CODE, msg, null);
    }

    public static JsonResult errorUpdate(Integer code, String msg) {
        return getResult(code, msg, null);
    }

    public static JsonResult errorUpdate(Integer code, String msg, Object obj) {
        return getResult(code, msg, obj);
    }


    public static JsonResult successIns() {
        return getResult(SUCCESS_CODE, INSERT_SUCCESS, null);
    }

    public static JsonResult successIns(String msg) {
        return getResult(SUCCESS_CODE, msg, null);
    }

    public static JsonResult successIns(Object object) {
        return getResult(SUCCESS_CODE, INSERT_SUCCESS, object);
    }

    public static JsonResult successIns(String msg, Object object) {
        return getResult(SUCCESS_CODE, msg, object);
    }

    public static JsonResult error(String msg) {
        return getResult(ERROR_CODE, msg, null);
    }

    public static JsonResult errorIns(String msg) {
        return getResult(ERROR_CODE, msg, null);
    }

    public static JsonResult errorIns(Integer code, String msg) {
        return getResult(code, msg, null);
    }

    public static JsonResult errorIns(Integer code, String msg, Object obj) {
        return getResult(code, msg, obj);
    }

    public static JsonResult getResult(Integer code, String msg, Object object) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(code);
        jsonResult.setMsg(msg);
        jsonResult.setData(object);
        JSON.toJSONString(jsonResult);
        return jsonResult;
    }
}
